package com.relatev.minecraft.UWantRestart.Bukkit;

import com.relatev.minecraft.UWantRestart.RestartCondition;
import org.bukkit.Bukkit;

public class FunctionModule implements Runnable {

    private static FunctionModule Instance;
    private static String KickMessage;

    public static void init() {
        Instance = new FunctionModule();
        Bukkit.getScheduler().runTaskTimer(UWantRestart.MainPlugin, Instance, 60 * 20, 60 * 20);
        for (RestartCondition rc : ConfigManager.RestartConditions) {
            if (rc.meetCondition(Bukkit.getOnlinePlayers().size())) {
                rc.StartIgnore = true;
            }
        }
        KickMessage = ConfigManager.config.getString("KickMessage");
    }

    @Override
    public void run() {
        for (RestartCondition rc : ConfigManager.RestartConditions) {
            if (rc.meetCondition(Bukkit.getOnlinePlayers().size())) {
                BKRestartTasker.restart(KickMessage, 30);
            } else {
                rc.StartIgnore = false;
            }
        }
    }
}
